function WindOfChange(){
		parameters = getParam();
		refreshList(
			filtr(list, checkObject, parameters), list
		)
}

function getParam(){
    var param = new Object();
	param.I1         = $('#chbI1').attr('checked');
    param.I2         = $('#chbI2').attr('checked');
    param.O          = $('#chbO').attr('checked');
    param.KURS       = $('#chbKURS').attr('checked');
    param.SEMINARIUM = $('#chbSEMINARIUM').attr('checked');
    param.ZALICZONE  = $("input[name='past']:checked").val();
	param.tag = $("#tag").val();
	return param;
}

function checkObject(obj, rule){
	koniec = false;
    if(strpos(obj.nazwa.toLowerCase(), rule.tag.toLowerCase())>=0 || rule.tag==''){
		koniec = true;
	}
    var koniecprim = false
	$.each(obj.prowadzacy, function(i, item){
		if(strpos(item.osoba.toLowerCase(), rule.tag.toLowerCase())>=0){
			koniecprim = true;
		}
	});
    koniec = koniec || koniecprim;
    
    if(obj.typ=='I1'){
        koniec = rule.I1&&koniec;
    };
    if(obj.typ=='I2'){
        koniec = rule.I2&&koniec;
    };
    if(obj.typ=='O'){
        koniec = rule.O&&koniec;
    };
    if(obj.typ=='KURS'){
        koniec = rule.KURS&&koniec;
    };     
    if(obj.typ=='SEMINARIUM'){
        koniec = rule.SEMINARIUM&&koniec;
    };
    if(obj.zaliczony=='TAK'){
        koniec = (rule.ZALICZONE=='A')&&koniec;
    };    
	return koniec;
}

function getObjectList(){
	var lista = new Array();
	
	
$.ajax({
    async: false,
    url: "lista",
    success: function(data) {
		   $.each(data.wpisy, function(i, item){
				lista.push(item);
		   });
    },
	dataType: "json"
});
	return lista;
}



function filtr(list, fun, param){
	a = list.length;
	var result = new Array();
	for(i=0;i<a;++i){
		result[i] = fun.call(this, list[i], param);
	}
	return result;
} 

function refreshList(StateList, ObjectList){
	size = StateList.length;
	for(i=0;i<size;++i){
	     var txt = '#'+ObjectList[i].id;
		if(StateList[i])
			$(txt).show();
	    else
			$(txt).hide();
	}
}

jQuery.create = function() {
    if (arguments.length == 0) return [];
    var args = arguments[0] || {}, elem = null, elements = null;
    var siblings = null;

    // In case someone passes in a null object,
    // assume that they want an empty string.
    if (args == null) args = "";
    if (args.constructor == String) {
        if (arguments.length > 1) {
            var attributes = arguments[1];
                if (attributes.constructor == String) {
                            elem = document.createTextNode(args);
                            elements = [];
                            elements.push(elem);
                            siblings =
        jQuery.create.apply(null, Array.prototype.slice.call(arguments, 1));
                            elements = elements.concat(siblings);
                            return elements;

                    } else {
                            elem = document.createElement(args);

                            // Set element attributes.
                            var attributes = arguments[1];
                            for (var attr in attributes)
                                jQuery(elem).attr(attr, attributes[attr]);

                            // Add children of this element.
                            var children = arguments[2];
                            children = jQuery.create.apply(null, children);
                            jQuery(elem).append(children);

                            // If there are more siblings, render those too.
                            if (arguments.length > 3) {
                                    siblings =
        jQuery.create.apply(null, Array.prototype.slice.call(arguments, 3));
                                    return [elem].concat(siblings);
                            }
                            return elem;
                    }
            } else return document.createTextNode(args);
      } else {
              elements = [];
              elements.push(args);
              siblings =
        jQuery.create.apply(null, (Array.prototype.slice.call(arguments, 1)));
              elements = elements.concat(siblings);
              return elements;
      }
};

function strpos (haystack, needle) {
    var i = (haystack+'').indexOf(needle);
    return i;
}